package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.PropertyLeaseInfo;
import com.ruoyi.system.service.IPropertyLeaseInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.service.ISysConfigService;

/**
 * 资产租借记录Controller
 * 
 * @author ruoyi
 * @date 2023-02-08
 */
@RestController
@RequestMapping("/system/leaseInfo")
public class PropertyLeaseInfoController extends BaseController
{
    @Autowired
    private IPropertyLeaseInfoService propertyLeaseInfoService;

    /**
     * 查询资产租借记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PropertyLeaseInfo propertyLeaseInfo)
    {
        startPage();
        List<PropertyLeaseInfo> list = propertyLeaseInfoService.selectPropertyLeaseInfoList(propertyLeaseInfo);
        return getDataTable(list);
    }

    /**
     * 导出资产租借记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:leaseInfo:export')")
    @Log(title = "资产租借记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PropertyLeaseInfo propertyLeaseInfo)
    {
        List<PropertyLeaseInfo> list = propertyLeaseInfoService.selectPropertyLeaseInfoList(propertyLeaseInfo);
        ExcelUtil<PropertyLeaseInfo> util = new ExcelUtil<PropertyLeaseInfo>(PropertyLeaseInfo.class);
        util.exportExcel(response, list, "资产租借记录数据");
    }

    /**
     * 获取资产租借记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:leaseInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(propertyLeaseInfoService.selectPropertyLeaseInfoById(id));
    }

    /**
     * 新增资产租借记录
     */
    @PreAuthorize("@ss.hasPermi('system:leaseInfo:add')")
    @Log(title = "资产租借记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PropertyLeaseInfo propertyLeaseInfo)
    {
        return toAjax(propertyLeaseInfoService.insertPropertyLeaseInfo(propertyLeaseInfo));
    }

    /**
     * 修改资产租借记录
     */
    @PreAuthorize("@ss.hasPermi('system:leaseInfo:edit')")
    @Log(title = "资产租借记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PropertyLeaseInfo propertyLeaseInfo)
    {
        return toAjax(propertyLeaseInfoService.updatePropertyLeaseInfo(propertyLeaseInfo));
    }

    /**
     * 归还
     */
    @PreAuthorize("@ss.hasPermi('system:leaseInfo:returnLeaseInfo')")
    @GetMapping(value = "/returnLeaseInfo/{id}")
    public AjaxResult returnLeaseInfo(@PathVariable("id") Long id)
    {
        return toAjax(propertyLeaseInfoService.returnLeaseInfo(id));
    }

    /**
     * 删除资产租借记录
     */
    @PreAuthorize("@ss.hasPermi('system:leaseInfo:remove')")
    @Log(title = "资产租借记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(propertyLeaseInfoService.deletePropertyLeaseInfoByIds(ids));
    }
}
